package com.example.huixingzheng.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.huixingzheng.R;
import com.example.huixingzheng.adapter.DeviceAdapter;
import com.example.huixingzheng.bean.DataModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能：
 * 作者：
 * 日期：2025年03月17日
 */
public class DeviceFragment extends Fragment {

    private RecyclerView recyclerView;
    private DeviceAdapter deviceAdapter;
    private List<DataModel> deviceList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_device, container, false);

        // 初始化 RecyclerView
        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // 准备数据
        deviceList = new ArrayList<>();
        // 这里可以添加实际的数据
        for (int i = 0; i < 10; i++)
        {
            DataModel device = new DataModel();
            device.setName("设备 " + (i + 1));
            device.setTemperature(20 + i);
            device.setHumidity(50 + i);
            device.setLight(100 + i);
            device.setSmoke(10 + i);
            deviceList.add(device);
        }

        // 创建 Adapter 并设置给 RecyclerView
        deviceAdapter = new DeviceAdapter(deviceList);
        recyclerView.setAdapter(deviceAdapter);

        return view;
    }
}